package com.langsotech.studio.pojo.infodirector.treeViewer;
import java.net.URL;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.graphics.Image;
import org.osgi.framework.Bundle;
import com.langsotech.studio.pojo.infodirector.data.PathName;
public class TreeViewerLabelProvider implements ILabelProvider {
	@Override
	public Image getImage(Object element) {
		if (element instanceof PathName) {
			switch (((PathName) element).getPathType()) {
			case PROJECT:
				return getDefaultPageImageDescriptor(
				"icons/fileEntity/project.jpg").createImage();
			case LOGIC:
				return getDefaultPageImageDescriptor(
						"icons/fileEntity/bizlogic.gif").createImage();
			case ACTION:
				return getDefaultPageImageDescriptor(
				"icons/fileEntity/presentation.gif").createImage();
			case WEBCONTENT:
				return getDefaultPageImageDescriptor(
				"icons/fileEntity/page.gif").createImage();	
			case TEMPLATE:
				return getDefaultPageImageDescriptor(
				"icons/fileEntity/page.gif").createImage();		
			case FOLDER:
				return getDefaultPageImageDescriptor(
				"icons/fileEntity/package.gif").createImage();
			}
		}
		return null;
	}
	@Override
	public String getText(Object element) {
		if (element instanceof PathName) {
			PathName pathName = (PathName) element;
			return pathName.getPathName();
		}
		return null;
	}
	@Override
	public void addListener(ILabelProviderListener arg0) {
	}
	@Override
	public void dispose() {
	}
	@Override
	public boolean isLabelProperty(Object arg0, String arg1) {
		return false;
	}
	@Override
	public void removeListener(ILabelProviderListener arg0) {
	}
	protected ImageDescriptor getDefaultPageImageDescriptor(String u) {
		final Bundle bundle = Platform
				.getBundle("com.langsotech.studio.pojo.infoDirector"); 
		final URL url = bundle.getEntry(u); 
		return ImageDescriptor.createFromURL(url);
	}
}
